package com.wn.ziroombackend.controller;


import com.github.pagehelper.PageInfo;
import com.wn.ziroombackend.entity.Quarters;
import com.wn.ziroombackend.service.QuartersService;
import com.wn.ziroombackend.utils.FtpUtil;
import com.wn.ziroombackend.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangzhijia
 * @since 2023-02-27 10:56:29
 */
@RestController
@RequestMapping("/quarters")
public class QuartersController {

    @Autowired
    private QuartersService quartersService;

    @RequestMapping("/getAll")
    public R getAll() {
        List<Quarters> list = quartersService.list();
        return R.ok("OK").data("quarterList", list);
    }

    @PostMapping("/list")
    public R list(@RequestParam(defaultValue = "1") Integer num,
                  @RequestParam(defaultValue = "2") Integer size, String name) {

        PageInfo<Quarters> quartersPageInfo = quartersService.getList(num, size, name);

        return R.ok("ok").data("quartersPageInfo", quartersPageInfo);

    }


    @PostMapping("/add")
    public R add(@RequestBody Quarters quarters) throws IOException {
        quartersService.save(quarters);
        return R.ok("ok");

    }

    @GetMapping("/getById/{id}")
    public R getById(@PathVariable Integer id) {
        Quarters byId = quartersService.getById(id);
        return R.ok("msg").data("quarters", byId);
    }

    @PostMapping("/edit")
    public R edit(@RequestBody Quarters quarters){
        quartersService.updateById(quarters);
        return R.ok("OK");

    }
}

